/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormListagemTarefas.java
 *
 * Created on 10/03/2012, 13:19:17
 */
package br.com.ufc.view;

import br.com.ufc.exception.IntegrationException;
import br.com.ufc.model.Tarefa;
import br.com.ufc.model.TarefaTableModel;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 * Classe que define o comportamento Formulario de listagem de tarefas
 * @author Paulo
 */
public class FormListagemTarefas extends javax.swing.JDialog {

    /**
     * Construtor da classe FormListagemTarefas
     */
    public FormListagemTarefas() {
        initComponents();
        inicializarComponentes();

        jtListaTarefas.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                atualizarDetalhes();
            }
        });
    }

    /**
     * Metodo responsavel por iniciar os componentes da tela
     */
    private void inicializarComponentes() {
        inicializarListagem();
        inicializarPanelEncerrar();
        jtfValorCobrado.setText("0.00");
    }

    private void inicializarPanelEncerrar() {
        jpEncerrarTarerfa.setVisible(false);
        jlAsterisco.setVisible(false);
    }

    private void atualizarDetalhes() {
        Tarefa t = null;
        Integer indice = null;
        try {
            indice = jtListaTarefas.getSelectedRow();
            if ((indice != null) && (indice.intValue() != -1)) {
                Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
                t = FormAgendaEti.agenda.consultarTarefa(cod);
            }
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }

        if ((indice != null) && (t != null) && (indice.intValue() != -1)) {
            if (t.getCodigo() != null) {
                jtfCodigoDetalhe.setText(t.getCodigo().toString());
            }
            if (t.getDescricao() != null) {
                jtfDescricao.setText(t.getDescricao().toUpperCase());
            }
            if (t.getData() != null) {
                jtfData.setText(t.getData());
            }
            if (t.getHoraInicio() != null) {
                jtfHoraInicio.setText(t.getHoraInicio());
            }
            if (t.getDuracao() != null) {
                jtfDuracao.setText(t.getDuracao().toString());
            }
            if (t.getValorHora() != null) {
                jtfValorHora.setText(t.getValorHora().toString());
            }
            if (t.getValorCobrado() != null) {
                jtfValorCobradoDetalhe.setText(t.getValorCobrado().toString());
            }
            if (t.getLocal() != null) {
                jtfLocal.setText(t.getLocal().toUpperCase());
            }
            if (t.getImportancia() != null) {
                jtfImportancia.setText(t.getImportancia().toString());
            }
            if (t.getUrgencia() != null) {
                jtfUrgencia.setText(t.getUrgencia().toString());
            }
        }

        if ((indice == null) || (indice.intValue() == -1)) {
            limparDetalhes();
        }
    }

    private void limparDetalhes() {
        jtfCodigoDetalhe.setText("");
        jtfDescricao.setText("");
        jtfData.setText("");
        jtfHoraInicio.setText("");
        jtfDuracao.setText("");
        jtfValorHora.setText("");
        jtfValorCobradoDetalhe.setText("");
        jtfLocal.setText("");
        jtfImportancia.setText("");
        jtfUrgencia.setText("");
    }

    private void consultar(String codigo) {
        DefaultTableModel dados = (DefaultTableModel) jtListaTarefas.getModel();

        Vector data = dados.getDataVector();
        Vector row = (Vector) data.elementAt(1);
        // Copy the first column
        int mColIndex = 0;
        List colData = new ArrayList(dados.getRowCount());
        for (int i = 0; i < dados.getRowCount(); i++) {
            row = (Vector) data.elementAt(i);
            colData.add(row.get(mColIndex));
        }

        colData.get(new Integer(codigo));

    }

    /**
     * Metodo responsavel por listar todas as tarefas da base da dados e atribuir ao jTable
     */
    private void inicializarListagem() {
        TarefaTableModel tarefaTModel = null;
        try {
            tarefaTModel = new TarefaTableModel(FormAgendaEti.agenda.listarTarefas().getListaTarefas());
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        jtListaTarefas.setModel(tarefaTModel);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        buttonGroup4 = new javax.swing.ButtonGroup();
        jpConsulta = new javax.swing.JPanel();
        jlConsulta = new javax.swing.JLabel();
        jlCodigo = new javax.swing.JLabel();
        jtfCodigo = new javax.swing.JTextField();
        jbConsultar = new javax.swing.JButton();
        jpListagem = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtListaTarefas = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jbIniciar = new javax.swing.JButton();
        jbEncerrar = new javax.swing.JButton();
        jbCancelar = new javax.swing.JButton();
        jbReiniciar = new javax.swing.JButton();
        jbRemover = new javax.swing.JButton();
        jpEncerrarTarerfa = new javax.swing.JPanel();
        jlValorCobrado = new javax.swing.JLabel();
        jtfValorCobrado = new javax.swing.JTextField();
        jlAsterisco = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jpA = new javax.swing.JPanel();
        jlCodigo1 = new javax.swing.JLabel();
        jtfCodigoDetalhe = new javax.swing.JTextField();
        jlDescricao = new javax.swing.JLabel();
        jtfDescricao = new javax.swing.JTextField();
        jpB = new javax.swing.JPanel();
        jlData = new javax.swing.JLabel();
        jtfData = new javax.swing.JTextField();
        jlHoraInicio = new javax.swing.JLabel();
        jtfHoraInicio = new javax.swing.JTextField();
        jlDuracao = new javax.swing.JLabel();
        jtfDuracao = new javax.swing.JTextField();
        jlValorHora = new javax.swing.JLabel();
        jtfValorHora = new javax.swing.JTextField();
        jlValorCobradoDetalhe = new javax.swing.JLabel();
        jtfValorCobradoDetalhe = new javax.swing.JTextField();
        jpC = new javax.swing.JPanel();
        jlLocal = new javax.swing.JLabel();
        jtfLocal = new javax.swing.JTextField();
        jlImportancia = new javax.swing.JLabel();
        jtfImportancia = new javax.swing.JTextField();
        jlUrgencia = new javax.swing.JLabel();
        jtfUrgencia = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jbIncImportancia = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator1 = new javax.swing.JSeparator();
        jPopupMenu1.getAccessibleContext().setAccessibleParent(jbEncerrar);

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Listagem de Tarefas");
        setResizable(false);

        jlConsulta.setFont(new java.awt.Font("Tahoma", 1, 12));
        jlConsulta.setText("Consulta");

        jlCodigo.setText("Código");

        jbConsultar.setText("Consultar");

        javax.swing.GroupLayout jpConsultaLayout = new javax.swing.GroupLayout(jpConsulta);
        jpConsulta.setLayout(jpConsultaLayout);
        jpConsultaLayout.setHorizontalGroup(
            jpConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpConsultaLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlConsulta)
                    .addGroup(jpConsultaLayout.createSequentialGroup()
                        .addComponent(jlCodigo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCodigo, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbConsultar)
                .addContainerGap())
        );
        jpConsultaLayout.setVerticalGroup(
            jpConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpConsultaLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jlConsulta)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpConsultaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jlCodigo)
                    .addComponent(jtfCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbConsultar)))
        );

        jtListaTarefas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "Título 1", "Título 2", "Título 3"
            }
        ));
        jScrollPane1.setViewportView(jtListaTarefas);
        jtListaTarefas.getColumnModel().getColumn(0).setResizable(false);
        jtListaTarefas.getColumnModel().getColumn(0).setPreferredWidth(5);
        jtListaTarefas.getColumnModel().getColumn(1).setResizable(false);
        jtListaTarefas.getColumnModel().getColumn(1).setPreferredWidth(20);
        jtListaTarefas.getColumnModel().getColumn(2).setResizable(false);
        jtListaTarefas.getColumnModel().getColumn(2).setPreferredWidth(5);

        jbIniciar.setText("Iniciar");
        jbIniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbIniciarActionPerformed(evt);
            }
        });

        jbEncerrar.setText("Encerrar");
        jbEncerrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEncerrarActionPerformed(evt);
            }
        });

        jbCancelar.setText("Cancelar");
        jbCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbCancelarActionPerformed(evt);
            }
        });

        jbReiniciar.setText("Reiniciar");
        jbReiniciar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbReiniciarActionPerformed(evt);
            }
        });

        jbRemover.setText("Remover");
        jbRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRemoverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(60, Short.MAX_VALUE)
                .addComponent(jbIniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEncerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbReiniciar, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbRemover, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(56, 56, 56))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                .addComponent(jbIniciar)
                .addComponent(jbEncerrar)
                .addComponent(jbCancelar)
                .addComponent(jbReiniciar)
                .addComponent(jbRemover))
        );

        jlValorCobrado.setText("Informe o valor cobrado:");

        jlAsterisco.setFont(new java.awt.Font("Tahoma", 1, 11));
        jlAsterisco.setText("*");

        javax.swing.GroupLayout jpEncerrarTarerfaLayout = new javax.swing.GroupLayout(jpEncerrarTarerfa);
        jpEncerrarTarerfa.setLayout(jpEncerrarTarerfaLayout);
        jpEncerrarTarerfaLayout.setHorizontalGroup(
            jpEncerrarTarerfaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpEncerrarTarerfaLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlValorCobrado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jlAsterisco)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jtfValorCobrado, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jpEncerrarTarerfaLayout.setVerticalGroup(
            jpEncerrarTarerfaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpEncerrarTarerfaLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jtfValorCobrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jlValorCobrado)
                .addComponent(jlAsterisco))
        );

        jlCodigo1.setText("Código:");

        jtfCodigoDetalhe.setEnabled(false);

        jlDescricao.setText("Descrição:");

        jtfDescricao.setEnabled(false);

        javax.swing.GroupLayout jpALayout = new javax.swing.GroupLayout(jpA);
        jpA.setLayout(jpALayout);
        jpALayout.setHorizontalGroup(
            jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpALayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlCodigo1)
                    .addComponent(jtfCodigoDetalhe, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlDescricao)
                    .addComponent(jtfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, 469, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jpALayout.setVerticalGroup(
            jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpALayout.createSequentialGroup()
                .addGroup(jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlDescricao)
                    .addComponent(jlCodigo1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpALayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCodigoDetalhe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpB.setPreferredSize(new java.awt.Dimension(384, 51));
        jpB.setRequestFocusEnabled(false);

        jlData.setText("Data:");

        jtfData.setEnabled(false);

        jlHoraInicio.setText("Hora de início:");

        jtfHoraInicio.setEnabled(false);

        jlDuracao.setText("Duração:");

        jtfDuracao.setEnabled(false);

        jlValorHora.setText("Valor da Hora:");

        jtfValorHora.setEnabled(false);

        jlValorCobradoDetalhe.setText("Valor Cobrado:");

        jtfValorCobradoDetalhe.setEnabled(false);

        javax.swing.GroupLayout jpBLayout = new javax.swing.GroupLayout(jpB);
        jpB.setLayout(jpBLayout);
        jpBLayout.setHorizontalGroup(
            jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpBLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfData, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
                    .addComponent(jlData))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfHoraInicio, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
                    .addComponent(jlHoraInicio))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlDuracao)
                    .addComponent(jtfDuracao, javax.swing.GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlValorHora)
                    .addComponent(jtfValorHora, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jtfValorCobradoDetalhe, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)
                    .addComponent(jlValorCobradoDetalhe))
                .addContainerGap())
        );
        jpBLayout.setVerticalGroup(
            jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpBLayout.createSequentialGroup()
                .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpBLayout.createSequentialGroup()
                        .addComponent(jlData)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpBLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jtfHoraInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpBLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jtfDuracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpBLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jtfValorHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jlHoraInicio)
                    .addComponent(jlDuracao)
                    .addGroup(jpBLayout.createSequentialGroup()
                        .addGroup(jpBLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlValorHora)
                            .addComponent(jlValorCobradoDetalhe))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfValorCobradoDetalhe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpC.setPreferredSize(new java.awt.Dimension(384, 51));

        jlLocal.setText("Local:");

        jtfLocal.setEnabled(false);

        jlImportancia.setText("Importância");

        jtfImportancia.setEnabled(false);

        jlUrgencia.setText("Urgência");

        jtfUrgencia.setEnabled(false);

        javax.swing.GroupLayout jpCLayout = new javax.swing.GroupLayout(jpC);
        jpC.setLayout(jpCLayout);
        jpCLayout.setHorizontalGroup(
            jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpCLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlLocal)
                    .addComponent(jtfLocal, javax.swing.GroupLayout.DEFAULT_SIZE, 374, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpCLayout.createSequentialGroup()
                        .addComponent(jlImportancia)
                        .addGap(40, 40, 40))
                    .addGroup(jpCLayout.createSequentialGroup()
                        .addComponent(jtfImportancia, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlUrgencia)
                    .addComponent(jtfUrgencia, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jpCLayout.setVerticalGroup(
            jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpCLayout.createSequentialGroup()
                .addGroup(jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpCLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(jpCLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfUrgencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfImportancia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jlUrgencia)
                    .addComponent(jlImportancia)
                    .addGroup(jpCLayout.createSequentialGroup()
                        .addComponent(jlLocal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfLocal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpA, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpB, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jpC, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpA, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpB, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(59, Short.MAX_VALUE))
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGap(126, 126, 126)
                    .addComponent(jpC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab("Detalhes", jPanel3);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Incrementar");

        jbIncImportancia.setText("Importância");
        jbIncImportancia.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbIncImportanciaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbIncImportancia, javax.swing.GroupLayout.PREFERRED_SIZE, 264, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbIncImportancia, javax.swing.GroupLayout.DEFAULT_SIZE, 119, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addContainerGap(312, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Operações", jPanel2);

        javax.swing.GroupLayout jpListagemLayout = new javax.swing.GroupLayout(jpListagem);
        jpListagem.setLayout(jpListagemLayout);
        jpListagemLayout.setHorizontalGroup(
            jpListagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpListagemLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpListagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpListagemLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jpEncerrarTarerfa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 611, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpListagemLayout.setVerticalGroup(
            jpListagemLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpListagemLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpEncerrarTarerfa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.getAccessibleContext().setAccessibleName("Operações");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jpConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jpListagem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpConsulta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpListagem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void atualizarListagem() {
        inicializarListagem();
    }

    private void jbIniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbIniciarActionPerformed
        try {
            int indice = jtListaTarefas.getSelectedRow();
            Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
            FormAgendaEti.agenda.iniciarTarefa(cod);
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        atualizarListagem();
    }//GEN-LAST:event_jbIniciarActionPerformed

    private void jbEncerrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEncerrarActionPerformed
        if (jpEncerrarTarerfa.isVisible()) {
            if ((jtfValorCobrado.getText() == null) || (jtfValorCobrado.getText().equals("0.00"))) {
                jlAsterisco.setVisible(true);
            } else {
                int indice = jtListaTarefas.getSelectedRow();
                Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
                try {
                    FormAgendaEti.agenda.encerrarTarefa(cod, new Double(jtfValorCobrado.getText()));
                    inicializarPanelEncerrar();
                    atualizarListagem();
                } catch (Exception ex) {
                    JOptionPane.showMessageDialog(this,
                            ex.getMessage(),
                            "Erro!", JOptionPane.ERROR_MESSAGE);
                }
            }
        } else {

            Object[] options = {"Sim", "Não"};
            int n = JOptionPane.showOptionDialog(null,
                    "Deseja encerrar todas as tarefas?",
                    "Encerrar tarefas", JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if (n == 0) {
                if (FormAgendaEti.agenda.encerrarTodasTarefas() == false) {
                    JOptionPane.showMessageDialog(this,
                            "Erro ao encerrar tarefas!",
                            "Erro!", JOptionPane.ERROR_MESSAGE);
                }
                atualizarListagem();
            } else {
                jpEncerrarTarerfa.setVisible(true);
            }
        }
        atualizarListagem();
    }//GEN-LAST:event_jbEncerrarActionPerformed

    private void jbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbCancelarActionPerformed
        try {
            int indice = jtListaTarefas.getSelectedRow();
            Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
            FormAgendaEti.agenda.cancelarTarefa(cod);
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        atualizarListagem();
    }//GEN-LAST:event_jbCancelarActionPerformed

    private void jbReiniciarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbReiniciarActionPerformed
        try {
            int indice = jtListaTarefas.getSelectedRow();
            Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
            FormAgendaEti.agenda.reiniciarTarefa(cod);
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        atualizarListagem();
    }//GEN-LAST:event_jbReiniciarActionPerformed

    private void jbIncImportanciaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbIncImportanciaActionPerformed
        try {
            int indice = jtListaTarefas.getSelectedRow();
            Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
            FormAgendaEti.agenda.incrementarImportancia(FormAgendaEti.agenda.consultarTarefa(cod));
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        atualizarDetalhes();
    }//GEN-LAST:event_jbIncImportanciaActionPerformed

    private void jbRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRemoverActionPerformed
        try {
            int indice = jtListaTarefas.getSelectedRow();
            Long cod = (Long) jtListaTarefas.getValueAt(indice, 0);
            FormAgendaEti.agenda.removerTarefa(cod);
        } catch (IntegrationException ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage(), "Erro!",
                    JOptionPane.ERROR_MESSAGE);
        }
        atualizarListagem();
    }//GEN-LAST:event_jbRemoverActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.ButtonGroup buttonGroup4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JButton jbCancelar;
    private javax.swing.JButton jbConsultar;
    private javax.swing.JButton jbEncerrar;
    private javax.swing.JButton jbIncImportancia;
    private javax.swing.JButton jbIniciar;
    private javax.swing.JButton jbReiniciar;
    private javax.swing.JButton jbRemover;
    private javax.swing.JLabel jlAsterisco;
    private javax.swing.JLabel jlCodigo;
    private javax.swing.JLabel jlCodigo1;
    private javax.swing.JLabel jlConsulta;
    private javax.swing.JLabel jlData;
    private javax.swing.JLabel jlDescricao;
    private javax.swing.JLabel jlDuracao;
    private javax.swing.JLabel jlHoraInicio;
    private javax.swing.JLabel jlImportancia;
    private javax.swing.JLabel jlLocal;
    private javax.swing.JLabel jlUrgencia;
    private javax.swing.JLabel jlValorCobrado;
    private javax.swing.JLabel jlValorCobradoDetalhe;
    private javax.swing.JLabel jlValorHora;
    private javax.swing.JPanel jpA;
    private javax.swing.JPanel jpB;
    private javax.swing.JPanel jpC;
    private javax.swing.JPanel jpConsulta;
    private javax.swing.JPanel jpEncerrarTarerfa;
    private javax.swing.JPanel jpListagem;
    private javax.swing.JTable jtListaTarefas;
    private javax.swing.JTextField jtfCodigo;
    private javax.swing.JTextField jtfCodigoDetalhe;
    private javax.swing.JTextField jtfData;
    private javax.swing.JTextField jtfDescricao;
    private javax.swing.JTextField jtfDuracao;
    private javax.swing.JTextField jtfHoraInicio;
    private javax.swing.JTextField jtfImportancia;
    private javax.swing.JTextField jtfLocal;
    private javax.swing.JTextField jtfUrgencia;
    private javax.swing.JTextField jtfValorCobrado;
    private javax.swing.JTextField jtfValorCobradoDetalhe;
    private javax.swing.JTextField jtfValorHora;
    // End of variables declaration//GEN-END:variables
}
